package com.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.model.auto.Tutorial;
import com.service.ITutorialService;
import com.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 操作视频
 * @author zhaoyifan
 * @date 2024/9/18 18:46
 */
@RestController
@RequestMapping("/open/tutorial")
public class TutorialController {

    @Autowired
    ITutorialService tutorialService;

    @GetMapping("/list")
    public R list(String type, Integer isLogin) {
        List<String> types = Arrays.asList(type.split(","));

        List<Tutorial> data = tutorialService.list(new LambdaQueryWrapper<Tutorial>()
                .in(Objects.nonNull(types), Tutorial::getType, types)
                .eq(Objects.nonNull(isLogin), Tutorial::getIsLogin, isLogin)
                .orderByAsc(Tutorial::getSortNum)
        );
        return R.ok(data);
    }
}
